//package com.kehutong.house.app;
//
//import java.util.Collections;
//import java.util.Comparator;
//import java.util.List;
//
//import com.kehutong.house.entity.BuildingDto;
//import com.kehutong.house.entity.Community;
//import com.kehutong.house.service.BuildService;
//import com.kehutong.house.util.CompareUtil;
//import org.coraframework.inject.Inject;
//import org.coraframework.json.JSONObject;
//import org.coraframework.mvc.MvcAction;
//import org.coraframework.mvc.http.ReqMapping;
//import org.coraframework.mvc.http.result.Result;
//import org.coraframework.orm.Pool;
//import org.coraframework.orm.jdbc.FindArray;
//import org.coraframework.orm.jdbc.SQLSession;
//
//import org.coraframework.util.Objects;
//
//@MvcAction
//@ReqMapping("/app/building")
//public class BuildingAction {
//
//    @Inject
//    private SQLSession sqlSession;
//    @Inject
//    private BuildService buildService;
//
//    @ReqMapping("/list")
//    public Object getBuildings(JSONObject jsonObject) {
////               List<Building> houses = sqlSession.findArray(Building.class)
////                    .eq(jsonObject, "communityNo", "level", "pid")
////                    .order("name", "ASC")
////                    .exe();
//        String communityNo = jsonObject.getString("communityNo");
//        if(Objects.isBlank(communityNo)){
//            return Result.error(0, "小区编号不能为空");
//        }
//        Community community = Pool.get(Community.class, communityNo);
//        if (Objects.isNull(community)) {
//            return Result.error(0, "请选择小区管理中创建的小区");
//        }
//        if(community.isDeleted()){
//            return Result.error(0, "该小区在小区管理中已删除");
//        }
//        String id = jsonObject.getString("id");
//        FindArray<BuildingDto> find = sqlSession.findArray(BuildingDto.class)
//                .eq("communityNo", communityNo)
//                .eq("deleted", false);
//
//        //建筑id为空,查询栋数据
//        if(Objects.isBlank(id)){
//            find.eq("level", 1);
//        }
//        else{
//            find.eq("pid", id);
//        }
//        List<BuildingDto> list = find.exe();
//        if(Objects.nonEmpty(list)){
//            Collections.sort(list, new Comparator<BuildingDto>() {
//                @Override
//                public int compare(BuildingDto o1, BuildingDto o2) {
//                    String a = o1.getName();
//                    String b = o2.getName();
//                    return CompareUtil.compareResult(a, b);
//                }
//            });
//            //list = buildService.handleBuildList(list);
//        }
//        return Result.success(list);
//    }
//}
